package net.zjitc.bookshop15.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.zjitc.bookshop15.mapper.userMapper;
import net.zjitc.bookshop15.pojo.loginUser;
import net.zjitc.bookshop15.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董熠涛
 * @date 2025/4/28 14:07
 */
@Slf4j
@Service
public class userDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private userMapper usermapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User userOne = usermapper.selectUserOne(username);

        List<String> perms = usermapper.selectUserPerms(userOne.getId());

        System.out.println("perms = " + perms);

        loginUser loginuser = new loginUser(userOne, perms);

        return loginuser;
    }
}
